package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.dao.SetMealDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : [chenxys]
 * @version : [v1.0]
 * @Description : 运营数据[统计服务]查询服务实现类
 * 不用加事物注解，因为只涉及查询
 * @createTime : [2022/6/2 09:16]
 */
@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    /**
     * 运营数据查询
     * @author chenxys
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    @Override
    public Map<String, Object> getBusinessReport() throws Exception {
        //存放最终返回的数据
        Map<String,Object> data = new HashMap<String,Object>();
        //报表日期
        String date = DateUtils.parseDate2String(DateUtils.getToday());
        //获得本周一的日期
        String monday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //今日会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(date);
        //总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        //本周新增会员数 周一到现在                            >本周一注册的会员
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(monday);
        //本月新增会员数
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDay4ThisMonth);

        //今日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(date);
        //今日就诊数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(date);
        //本周预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(monday);
        //本周就诊数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(monday);
        //本月预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);
        //本月就诊数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);

        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();


        //存入日期
        data.put("reportDate",date);
        //存入今日会员
        data.put("todayNewMember",todayNewMember);
        //存入总会员数
        data.put("totalMember",totalMember);
        //存入本周新增会员数
        data.put("thisWeekNewMember",thisWeekNewMember);
        //存入本月新增会员数
        data.put("thisMonthNewMember",thisMonthNewMember);
        //存入今日预约数
        data.put("todayOrderNumber",todayOrderNumber);
        //存入今日就诊数
        data.put("todayVisitsNumber",todayVisitsNumber);
        //存入本周预约数
        data.put("thisWeekOrderNumber",thisWeekOrderNumber);
        //存入本周就诊数
        data.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        //存入本月预约数
        data.put("thisMonthOrderNumber",thisMonthOrderNumber);
        //存入本周就诊数
        data.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        //存入热门套餐
        data.put("hotSetmeal",hotSetmeal);
        return data;
    }
}
